dcmotor28fng 2.2.1
Loading...
Searching...
No Matches
dcmotor28fng.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef DCMOTOR28FNG_H
29#define DCMOTOR28FNG_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52
58
63
68
73#define DCMOTOR28FNG_RISENSE_V_TO_MA 1.0
74
79#define DCMOTOR28FNG_NUM_CONVERSIONS 200
80
85#define DCMOTOR28FNG_VREF_3V3 3.3
86#define DCMOTOR28FNG_VREF_5V 5.0
87#define DCMOTOR28FNG_VREF_DEFAULT DCMOTOR28FNG_VREF_3V3
88
93#define DCMOTOR28FNG_TIMEOUT_MS 2000
94
99#define DCMOTOR28FNG_MOTOR_COAST 0
100#define DCMOTOR28FNG_MOTOR_FORWARD 1
101#define DCMOTOR28FNG_MOTOR_REVERSE 2
102#define DCMOTOR28FNG_MOTOR_BRAKE 3
103 // dcmotor28fng_set
105
110
115
120#define DCMOTOR28FNG_MAP_MIKROBUS( cfg, mikrobus ) \
121 cfg.isense = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122 cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_RST ); \
123 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
124 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
125 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
126 // dcmotor28fng_map // dcmotor28fng
129
134typedef struct
135{
136 digital_out_t sleep;
137 digital_out_t in1;
138 digital_out_t in2;
139
140 digital_in_t fault;
141
142 analog_in_t adc;
143
145
147
152typedef struct
153{
154 pin_name_t isense;
155 pin_name_t sleep;
156 pin_name_t in1;
157 pin_name_t in2;
158 pin_name_t fault;
159
160 analog_in_resolution_t resolution;
161 float vref;
162
164
175
181
192
207
219err_t dcmotor28fng_read_adc_raw ( dcmotor28fng_t *ctx, uint16_t *data_out );
220
234err_t dcmotor28fng_read_adc_volt ( dcmotor28fng_t *ctx, float *data_out );
235
249err_t dcmotor28fng_read_adc_volt_avg ( dcmotor28fng_t *ctx, uint16_t num_conv, float *volt_avg );
250
262err_t dcmotor28fng_set_adc_vref ( dcmotor28fng_t *ctx, float vref );
263
273
283
293
303
313
323
333
346void dcmotor28fng_drive_motor ( dcmotor28fng_t *ctx, uint8_t state );
347
359
371err_t dcmotor28fng_get_out_current ( dcmotor28fng_t *ctx, float *current );
372
373#ifdef __cplusplus
374}
375#endif
376#endif // DCMOTOR28FNG_H
377 // dcmotor28fng
379
380// ------------------------------------------------------------------------ END
dcmotor28fng_return_value_t
DC Motor 28 FNG Click return value data.
Definition dcmotor28fng.h:170
@ DCMOTOR28FNG_ERROR
Definition dcmotor28fng.h:172
@ DCMOTOR28FNG_OK
Definition dcmotor28fng.h:171
void dcmotor28fng_drive_motor(dcmotor28fng_t *ctx, uint8_t state)
DC Motor 28 FNG drive motor function.
uint8_t dcmotor28fng_get_fault_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG get FAULT pin function.
void dcmotor28fng_clear_in2_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG clear IN2 pin function.
err_t dcmotor28fng_get_out_current(dcmotor28fng_t *ctx, float *current)
DC Motor 28 FNG get out current function.
void dcmotor28fng_clear_in1_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG clear IN1 pin function.
void dcmotor28fng_set_in2_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG set IN2 pin function.
void dcmotor28fng_set_in1_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG set IN1 pin function.
err_t dcmotor28fng_read_adc_volt_avg(dcmotor28fng_t *ctx, uint16_t num_conv, float *volt_avg)
DC Motor 28 FNG read ISENSE pin voltage level average function.
void dcmotor28fng_set_sleep_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG set SLEEP pin function.
void dcmotor28fng_clear_sleep_pin(dcmotor28fng_t *ctx)
DC Motor 28 FNG clear SLEEP pin function.
err_t dcmotor28fng_calib_offset(dcmotor28fng_t *ctx)
DC Motor 28 FNG calib offset function.
err_t dcmotor28fng_read_adc_volt(dcmotor28fng_t *ctx, float *data_out)
DC Motor 28 FNG read ISENSE pin voltage level function.
err_t dcmotor28fng_read_adc_raw(dcmotor28fng_t *ctx, uint16_t *data_out)
DC Motor 28 FNG read raw ISENSE ADC value function.
err_t dcmotor28fng_init(dcmotor28fng_t *ctx, dcmotor28fng_cfg_t *cfg)
DC Motor 28 FNG initialization function.
err_t dcmotor28fng_set_adc_vref(dcmotor28fng_t *ctx, float vref)
DC Motor 28 FNG set vref function.
void dcmotor28fng_cfg_setup(dcmotor28fng_cfg_t *cfg)
DC Motor 28 FNG configuration object setup function.
DC Motor 28 FNG Click configuration object.
Definition dcmotor28fng.h:153
pin_name_t sleep
Definition dcmotor28fng.h:155
analog_in_resolution_t resolution
Definition dcmotor28fng.h:160
float vref
Definition dcmotor28fng.h:161
pin_name_t in2
Definition dcmotor28fng.h:157
pin_name_t isense
Definition dcmotor28fng.h:154
pin_name_t in1
Definition dcmotor28fng.h:156
pin_name_t fault
Definition dcmotor28fng.h:158
DC Motor 28 FNG Click context object.
Definition dcmotor28fng.h:135
digital_out_t sleep
Definition dcmotor28fng.h:136
digital_out_t in2
Definition dcmotor28fng.h:138
digital_in_t fault
Definition dcmotor28fng.h:140
float zero_curr_offset
Definition dcmotor28fng.h:144
digital_out_t in1
Definition dcmotor28fng.h:137
analog_in_t adc
Definition dcmotor28fng.h:142